#ifndef _L2TP_H_
#define	_L2TP_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/wait.h>

#include "list.h"

/// Use for making the socket link.
//#define PEER_LISTEN_PORT		7654 
//#define SNMP_LISTEN_PORT		7655
#define PEER_LISTEN_PORT		99 
#define SNMP_LISTEN_PORT		98

#define BUFFER_SIZE 1024
#define SIZE_512	512
#define SIZE_256	256
#define SIZE_128	128
#define SIZE_64		64
#define SIZE_32		32

/*  Some num start point. */
#define TUNNEL_ID_START 		1
#define SESSION_ID_START 		10000
#define SOURCE_PORT_START		8001

/* L2TP peer message types */
/* Peer request , we send some id  back .*/

#define PEER_REQUST				"request" 
/* Peer l2tp create success. */	 
#define PEER_CREATE_SUCCESS		2 
/* Peer DSL recover ,tell us .*/
#define PEER_DSL_RECOVER		"link_recover"

/*	End define peer message type	*/


/* SNMP message typedef */
#define SNMP_ADD				"add"
#define SNMP_DEL				"rem"

#define SNMP_VLAN_H				"vlan"
#define SNMP_L2TP_H				"l2tp"
#define SNMP_PUBLIC_IP_CHANGE	"changePublicIp"
#define SNMP_SHOW_VLAN			"show"

#define L2TP_ADD_SHELL			"/tmp/l2tp_add.sh"
#define HANDLE_L2TP_SHELL		"/tmp/handle_l2tp.sh"

#define ADD_L2TP_RULES			\
	"#!/bin/bash\n\n" \
    "ip l2tp add tunnel tunnel_id %d peer_tunnel_id %d encap udp local %s remote %s udp_sport %d udp_dport %d\n" \
    "ip l2tp add session tunnel_id %d session_id %d peer_session_id %d name %s\n" \
    "ip link set %s up\n" \
    "\n"
	
	
//    "brctl addif br0 %s\n" 

#define ADD_IP_EBTABLE					\
	"ebtables -P INPUT ACCEPT\n"   		\
	"ebtables -P OUTPUT ACCEPT\n"		\
	"ebtables -P FORWARD ACCEPT\n"		\
	"iptables -P INPUT ACCEPT\n"		\
	"iptables -P OUTPUT ACCEPT\n"		\
	"iptables -P FORWARD ACCEPT\n"		\
	
#define DEL_L2TP_RULES		\
	"#!/bin/bash\n\n" \
	"ip l2tp del session tunnel_id %d session_id %d \n"	\
	"ip l2tp del tunnel tunnel_id %d \n"
	
/*	End if define SNMP message type */

/*
struct l2tp_info
{
	char l2tp_inface_name[SIZE_64] ;	//l2tp's interface name
	char tunnel_id[SIZE_32] ; 		//local tunnel id ;
	char peer_tunnel_id[SIZE_32] ; 		//peer tunnel id 	
	char session_id[SIZE_32] ;		//local session id 
	char peer_session_id[SIZE_32] ;		//remote session id
	char local_ip[SIZE_64] ;		//local ip address
	char remote_ip[SIZE_64] ;		//remote ip address
	char source_port[SIZE_32] ;		//source port
	char dest_port[SIZE_32] ;			//destination port
	char mac_addr[SIZE_64] ;		//peer MAC address
	char inface_name[SIZE_64] ;			//this side's vlan id .link with the l2tp interface
	char vlan_id[SIZE_128] ;
//	struct l2tp_info *next ;
	struct list_head list ;
};
*/

/* declaration function from link.c */
//extern struct l2tp_info *create_link_list(void) ;
//extern void print_list(struct l2tp_info *head) ;
//extern int insert_link_list(struct l2tp_info **head, struct l2tp_info *insert) ;
//extern struct l2tp_info  *insert_link_list(struct l2tp_info *head, struct l2tp_info *insert) ;

/*declaration function from function.c*/
extern char * trim(char src[]) ;
extern FILE *mypopen(char *cmd,char type) ;
extern int chmod_excute_mypopen(char *file ) ;
extern int excute_mypopen(char cmd[]) ;
extern void excute_delbr(int br_flag) ;

#endif
